package com.sgcc.sx.pmos.common.utils;

import java.util.HashMap;
import java.util.Map;

/**
 * @author svs:
 * @version 创建时间：2016-12-16 下午02:28:23
 * 类说明
 */
public class ListPageUtil {

    /**
     * 每页条数
     */
    public static int pageSize = 10;
//    public static int pageSize = 1;

    /**
     * 总页数
     */
    private int totalPage;

    /**
     * 总数据条数
     */
    private int totalCount;

    public ListPageUtil(int size, int pagecount) {
        if (size > 0) {
            this.totalCount = size;
            this.totalPage = (totalCount + pagecount - 1) / pagecount + 1;
        } else {
            this.totalPage = 1;
        }

    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public static Map<String, Object> getPageInfo(int listsize) {
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("pageNum", new ListPageUtil(listsize, ListPageUtil.pageSize).getTotalPage());
        params.put("pageSize", ListPageUtil.pageSize);
        return params;
    }

    public static boolean isHasNextPage(int total, int listsize) {
        int num = 0;
        if (total == 0) {
            return false;
        }
        if (total % ListPageUtil.pageSize != 0) {
            num = total / ListPageUtil.pageSize + 1;
        } else {
            num = total / ListPageUtil.pageSize;
        }
        int pageNum = new ListPageUtil(listsize, ListPageUtil.pageSize).getTotalPage();
        if (pageNum == num) {
            return false;
        } else {
            return true;
        }
    }
}

